Skip to content

Conversation

@mt82
Copy link
Contributor

@mt82 mt82 commented Dec 23, 2025

Default initialization values have been introduced for all CRTHit data members. This change ensures that variables are properly initialized at object creation, reducing the risk of undefined behavior and improving code reliability.

@mt82 mt82 linked an issue Dec 23, 2025 that may be closed by this pull request
@mt82 mt82 changed the title added initialization added initialization to CRTHit data members Dec 23, 2025
Copy link
Contributor

@kjplows kjplows left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me thanks! I'll let @PetrilloAtWork decide if using flavours of 0 is better than calling on std::numeric_limits<T> here; my one comment is if any CRT variables are expected to be 0 physically (looking at ts0_ns, x_pos etc) probably std::numeric_limits::lowest() is easier to interpret as nonsense.

Copy link
Member

@PetrilloAtWork PetrilloAtWork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stupid GitHub ate my comment.

Which boiled down to: agree with @kjplows, define static constexpr double kInvalidD = std::numeric_limits<double>::lowest(); and kInvalidF for float, use those to initialise, and use -1 as plane value.

"Stupid GitHub" was an euphemism, by the way.

Comment on lines +25 to +26
std::vector<uint8_t> feb_id{}; ///< FEB address
std::map< uint8_t, std::vector<std::pair<int,float> > > pesmap{}; ///< Saves signal hit information (FEB, local-channel and PE) .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These ones are actually not needed: non-basic types have their constructor called.

Suggested change
std::vector<uint8_t> feb_id{}; ///< FEB address
std::map< uint8_t, std::vector<std::pair<int,float> > > pesmap{}; ///< Saves signal hit information (FEB, local-channel and PE) .
std::vector<uint8_t> feb_id; ///< FEB address
std::map< uint8_t, std::vector<std::pair<int,float> > > pesmap; ///< Saves signal hit information (FEB, local-channel and PE) .

std::string tagger{}; ///< Name of the CRT wall (in the form of strings).

CRTHit() {}
CRTHit() = default;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just remove this, nobody will miss it.

Suggested change
CRTHit() = default;

float z_err{0.f}; ///< position uncertainty in z-direction (cm).

std::string tagger; ///< Name of the CRT wall (in the form of strings).
std::string tagger{}; ///< Name of the CRT wall (in the form of strings).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, std::string constructor will be called and ensures an empty string.

Suggested change
std::string tagger{}; ///< Name of the CRT wall (in the form of strings).
std::string tagger; ///< Name of the CRT wall (in the form of strings).

Copy link
Member

@PetrilloAtWork PetrilloAtWork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stupid GitHub ate my comment.

Which boiled down to: agree with @kjplows, define static constexpr double kInvalidD = std::numeric_limits<double>::lowest(); and kInvalidF for float, use those to initialise, and use -1 as plane value.

"Stupid GitHub" was an euphemism, by the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Partially reviewed

Development

Successfully merging this pull request may close these issues.

CRTHit struct members not initialized

4 participants